package com.suxin.datahub.controller;

import com.suxin.datahub.database.DataBaseFactory;
import com.suxin.datahub.domain.DataSourceDomain;
import com.suxin.datahub.core.DataBaseMetaService;
import com.suxin.datahub.util.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname DataSourceController
 * @Description [ DataSourceController ]
 * @Author Tang
 * @Date 2020/11/10 13:21
 * @Created by ASUS
 */
@RequestMapping("/datasource")
@RestController
public class DataSourceController {

    @PostMapping("/test")
    public ResponseResult<Boolean> testConnection(@RequestBody DataSourceDomain dataSourceDomain) {
        DataBaseMetaService metaService = DataBaseFactory.getMetaService(dataSourceDomain);
        return ResponseResult.Ok(metaService.testConnection() != null);
    }

}